﻿using Abp.Dependency;
using Abp.Threading.BackgroundWorkers;
using Abp.Threading.Timers;
using ARchGL.Platform.Configuration;
using ARchGL.Platform.Sessions;
using Microsoft.Extensions.Options;
using System.Threading;

namespace ARchGL.Platform.BackgroundWorker
{
    /// <summary>
    /// 刷新 SpdierBIM AccessToken
    /// </summary>
    public class RefreshSpiderTokenWorker : PeriodicBackgroundWorkerBase, ISingletonDependency
    {
        private readonly SpiderConfigOptions spiderConfigOptions;

        public RefreshSpiderTokenWorker(AbpTimer timer, IOptions<SpiderConfigOptions> _spiderConfigOptions) : base(timer)
        {
            spiderConfigOptions = _spiderConfigOptions.Value;
            Timer.Period = 3000000; //50分钟一次
            //Timer.Period = 5000;

            Thread.Sleep(1000);
            DoWork(); //启动时第一次请求
        }

        protected override void DoWork()
        {
            spiderConfigOptions.RefreshToken(); //刷新 Token
        }
    }
}
